﻿Imports System.Data.SqlClient
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub SinhViênToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SinhViênToolStripMenuItem.Click
        Dim lp = New Lop()
        lp.MdiParent = Me
        lp.Show()

    End Sub

    Private Sub MônHọcToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MônHọcToolStripMenuItem.Click
        Dim mh = New DanhSachMonHoc()
        mh.MdiParent = Me
        mh.Show()
    End Sub

    Private Sub ThoátToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ThoátToolStripMenuItem.Click
        Application.Exit()
    End Sub

    Private Sub LớpToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LớpToolStripMenuItem.Click
        Dim dlp = New DanhSachLop()
        dlp.MdiParent = Me
        dlp.Show()
    End Sub

    Private Sub ĐăngXuấtToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ĐăngXuấtToolStripMenuItem.Click
        DisableMenu()
    End Sub

    Private Sub QuảnLýNgườiDùngToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuảnLýNgườiDùngToolStripMenuItem.Click
        Dim qlnd = New DangNhap()
        qlnd.MdiParent = Me
        qlnd.Show()
    End Sub
    Public Sub DisableMenu()
        SinhViênToolStripMenuItem.Enabled = False
        LớpToolStripMenuItem.Enabled = False
        MônHọcToolStripMenuItem.Enabled = False
        ĐiểmToolStripMenuItem.Enabled = False
        TìmKiếmSinhViênToolStripMenuItem.Enabled = False
    End Sub
    Public Sub EnableMenu()
        SinhViênToolStripMenuItem.Enabled = True
        LớpToolStripMenuItem.Enabled = True
        MônHọcToolStripMenuItem.Enabled = True
        ĐiểmToolStripMenuItem.Enabled = True
        TìmKiếmSinhViênToolStripMenuItem.Enabled = True
    End Sub

    Private Sub SaoLưuDữLiệuToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaoLưuDữLiệuToolStripMenuItem.Click

        Try
            Dim con As SqlConnection = New SqlConnection()
            con.ConnectionString = Ketnoi.str
            con.Open()
            Dim cmd As SqlCommand = New SqlCommand()
            cmd.Connection = con
            cmd.CommandText = "BACKUP DATABASE [QuanLySinhVien] TO DISK='E:\\backup.bak'"
            cmd.ExecuteNonQuery()
            con.Close()
            MessageBox.Show("Backup Database Quản Lý Sinh Viên Thành Công!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As SqlException
            MessageBox.Show(ex.ToString(), "BACKUP DATABASE")
            Return
        End Try

    End Sub


    Private Sub ĐăngNhậpToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles ĐăngNhậpToolStripMenuItem.Click
        Dim frm As New DangNhapHeThong()
        frm.Show()
    End Sub

    Private Sub PhụcHồiDữLiệuToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles PhụcHồiDữLiệuToolStripMenuItem.Click

        Try
            Dim con As SqlConnection = New SqlConnection()
            con.ConnectionString = Ketnoi.str
            con.Open()
            Dim strpath As String = "E:\\backup.bak"
            Dim cmd As SqlCommand = New SqlCommand()
            cmd.Connection = con
            cmd.CommandText = "USE master RESTORE DATABASE [QuanLySinhVien] FROM DISK='" + strpath + "'"
            cmd.ExecuteNonQuery()
            con.Close()
            MessageBox.Show("Restore Database Quản Lý Sinh Viên Thành Công!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As SqlException
            MessageBox.Show(ex.ToString(), "ERROR RESTORE DATABASE")
            Return
        End Try

    End Sub

    Private Sub TìmKiếmSinhViênToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles TìmKiếmSinhViênToolStripMenuItem.Click
        Dim frm As TimKiemSinhVien = New TimKiemSinhVien()
        frm.MdiParent = Me
        frm.Show()

    End Sub
End Class